package com.qcnh.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcnh.entity.Reservation;
import com.qcnh.mapper.ReservationMapper;
import com.qcnh.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import unil.Result;

import java.util.List;

/**
 * <p>
 * 预约表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2024-12-05
 */
@Service
public class ReservationServiceImpl extends ServiceImpl<ReservationMapper, Reservation> implements ReservationService {
    @Autowired
    private  ReservationMapper reservationMapper;

    //分页查询预约信息，并支持根据用户id模糊查询
    @Override
    public IPage<Reservation> selectAllReservations(Integer current, Integer size, String keyWord) {
        Page<Reservation> page = new Page<>(current,size);//创建分页对象
        QueryWrapper<Reservation> wrapper = new QueryWrapper<>();//创建查询对象
        if (StringUtils.isNotBlank(keyWord)) {//判空并模糊查询：假设根据用户id搜索
            wrapper.like("user_id",keyWord);
        }
        return reservationMapper.selectPage(page,wrapper);//使用mybatis自带的模糊分页查询方法。
    }

    //添加预约
    @Override
    public  Boolean addReservation(Reservation reservation) {
        return reservationMapper.insert(reservation)>0?true:false; //使用mybatis自带的插入方法
    }

    @Override
    public  Boolean delReservationsByIdList(List<Integer> reservationIds) {
        return reservationMapper.deleteBatchIds(reservationIds) > 0 ? true : false;//使用mybatis自带的批量删除方法
    }

    @Override
    public  Boolean updateReservation(Reservation reservation) {
        return reservationMapper.updateById(reservation) > 0 ? true : false;
    }
}
